package com.project.mapper;

import com.project.bean.RecordBean;
import org.apache.ibatis.annotations.*;

import javax.swing.plaf.LabelUI;
import java.util.List;

public interface IRecordMapper {
    /**根据房间id查房间损坏记录，状态为为解决
     *
     * @param id 房间
     * @return 记录集合
     */
    @Select(" SELECT * FROM t_record WHERE fk_roomId = #{id}")
    @ResultMap("find")
    List<RecordBean> findByRoomId(Integer id);

    /*增加房间设施记录
     * 同时将该房间状态变为设备损坏
     * */
    @Insert("INSERT INTO t_record(r_descride,fk_roomId) VALUES(#{record},#{roomId})")
    void addRecord(@Param("record") String record, @Param("roomId") Integer roomId);
    @Update("UPDATE t_room SET r_status ='损坏' WHERE pk_roomId=#{roomId};")
    void updateStatus(Integer roomId);


    /*处理已损坏记录，
     * 按设施ID将解决状态修改为”已解决“
     * 按房间id统计”未解决“设施数量，如果为0，则修改房间状态为正常
     *
     * */
    @Insert("UPDATE t_record SET r_status ='已解决' WHERE pk_Id=#{recordId}")
    void updateRecord(@Param("recordId") Integer recordId,@Param("roomId") Integer roomId);

//    统计设施为解决数量
    @Select("select * from t_record where fk_roomid = #{id} and r_status = '未解决'")
    @ResultMap("find")
    List<RecordBean> findByRoomIdStatus(Integer id);

//    修改房间状态
    @Insert("UPDATE t_room SET r_status ='正常' WHERE pk_roomId=#{id}")
    void upRoomStatus(Integer id);



}
